//EQUALIZAÇÃO DE HISTOGRAMA IMPLEMENTADA

void NewspaperSegmentation::computeStep1Image(){
	if( image_step[1] ){
		setCurrentImage( 1 );
		return;
	}
	//implementar equalização de histograma aqui
	
	double n[256];
	double prob_r[256];
	double S[256];
	
	for( int k = 0; k < 256; ++k ){
		n[k] = 0;
		S[k] = 0;
	}
	
	for( int y = 0; y < image_step[0]->height(); ++y ){
		for( int x = 0; x < image_step[0]->width(); ++x ){
			int k = qRed(image_step[0]->pixel( x, y ));
			n[k] += 1;
		}
	}

	double MN = image_step[0]->width()*image_step[0]->height();

	for( int k = 0; k < 256; ++k )
		prob_r[k] = n[k] / MN;
	
	for( int k = 0; k < 256; ++k ){
		for( int i = 0; i <= k; ++i )
			S[k] += 255*prob_r[i];
		S[k] = round(S[k]);
	}
	
	image_step[1] = new QImage( image_step[0]->width(), image_step[0]->height(), QImage::Format_RGB32 );
	for( int y = 0; y < image_step[0]->height(); ++y ){
		for( int x = 0; x < image_step[0]->width(); ++x ){
			int k = qRed(image_step[0]->pixel( x, y ));
			image_step[1]->setPixel( x, y, QColor( S[k], S[k], S[k] ).rgb() );
		}
	}
	
	//for( int y = 0; y < image_step[0]->height(); ++y ){
	//	for( int x = 0; x < image_step[0]->width(); ++x ){
	//		int k = qRed(image_step[0]->pixel( x, y ));
	//		image_step[1]->setPixel( x, y, QColor( k, k, k ).rgb() );
	//	}
	//}
	//término da implementação
	
	setCurrentImage( 1 );
}

